﻿using rmTest.Common.ModelUtil;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace rmTest.Common
{
    public class ExpressionTreeVisualizer
    {
        public static void Show()
        {
            {
                Expression<Func<SqlDataReader, object>> lambda = p => p.GetValue(0) is DBNull ? null : p.GetValue(0);
                //{
                //    Type type = typeof(BaseModel);
                //    BaseModel t = Activator.CreateInstance<BaseModel>();
                //    PropertyInfo[] propertys = type.GetProperties();
                //    foreach (PropertyInfo property in propertys)
                //    {
                //        property.SetValue(t, p[1] is DBNull ? null : p[1]);
                //    }
                //    return t;
                //};// p[1] is DBNull ? null : p[1];
            }
            {
                //ParameterExpression expression;
                //Expression[] arguments = new Expression[] { Expression.Constant(0, typeof(int)) };
                //Expression[] expressionArray2 = new Expression[] { Expression.Constant(0, typeof(int)) };
                //ParameterExpression[] parameters = new ParameterExpression[] { expression };
                //Expression<Func<SqlDataReader, object>> lambda = Expression.Lambda<Func<SqlDataReader, object>>(Expression.Condition(Expression.TypeIs(Expression.Call(expression = Expression.Parameter(typeof(SqlDataReader), "p"), (MethodInfo)methodof(DbDataReader.GetValue), arguments), typeof(DBNull)), Expression.Constant(null, typeof(object)), Expression.Call(expression, (MethodInfo)methodof(DbDataReader.GetValue), expressionArray2)), parameters);
            }
            {
                //ParameterExpression parameterExpression = Expression.Parameter(typeof(SqlDataReader), "p");
                //Expression<Func<SqlDataReader, object>> expression = Expression.Lambda<Func<SqlDataReader, object>>(Expression.Condition(Expression.TypeIs(Expression.Call(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(ldtoken(GetValue())), new Expression[]
                //{
                //Expression.Constant(0, typeof(int))
                //}), typeof(DBNull)), Expression.Constant(null, typeof(object)), Expression.Call(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(ldtoken(GetValue())), new Expression[]
                //{
                //Expression.Constant(0, typeof(int))
                //})), new ParameterExpression[]
                //{
                //parameterExpression
                //});
            }

        }
    }
}
